//                       .::::.
//                     .::::::::.
//                    :::::::::::
//                 ..:::::::::::'
//              '::::::::::::'
//                .::::::::::
//           '::::::::::::::..
//                ..::::::::::::.
//              ``::::::::::::::::
//               ::::``:::::::::'        .:::.
//              ::::'   ':::::'       .::::::::.
//            .::::'      ::::     .:::::::'::::.
//           .:::'       :::::  .:::::::::' ':::::.
//          .::'        :::::.:::::::::'      ':::::.
//         .::'         ::::::::::::::'         ``::::.
//     ...:::           ::::::::::::'              ``::.
//    ```` ':.          ':::::::::'                  ::::..
//                       '.:::::'                    ':'````..
package com.xw.controller.api;

import com.google.common.collect.Maps;
import com.xw.common.Const;
import com.xw.service.BannerService;
import com.xw.util.AppUtil;
import com.xw.util.JsonData;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.Map;

@Controller
@RequestMapping("/api/banner/")
@Scope("prototype")
public class ApiBannerController {

    @Resource
    private BannerService bannerService;

    /**
     * 首页搜索 - 小程序
     * @param userId        用户id
     * @param searchName    搜索条件
     * @param type          类型 1.课程 2.导师
     * @param page
     * @param limit
     * @return
     */
    @RequestMapping(value = "findHomeSearchMP",method = RequestMethod.POST)
    @ResponseBody
    public Object findHomeSearchMP(String userId,String searchName,Integer type,Integer page,Integer limit){
        Map paramsMap = Maps.newHashMap();
        paramsMap.put("type",type);
        //判断传参
        String str = AppUtil.checkIsNull(paramsMap);
        if (!str.equals(Const.SUCCESS_CODE_STR)) {
            return JsonData.fail(Const.parameterError(str));
        }
        Map map = bannerService.findHomeSearchMP(userId,searchName,type,page,limit);
        return map;
    }

    /**
     * 首页-数据小程序
     * @return
     */
    @RequestMapping(value = "findHomeMP",method = RequestMethod.POST)
    @ResponseBody
    public Object findHomeMP(String userId){
        Map map = bannerService.findHomeMP(userId);
        return map;
    }

    /**
     * 首页数据
     * @return
     */
    @RequestMapping(value = "findHome",method = RequestMethod.POST)
    @ResponseBody
    public Object findHome(){
        Map map = bannerService.findHome();
        return map;
    }

    /**
     * 首页轮播图
     * @param page      页数
     * @param limit     条数
     * @return
     */
    @RequestMapping(value = "findBanner",method = RequestMethod.POST)
    @ResponseBody
    public Object findBanner(Integer page,Integer limit){
        Map map = bannerService.findBanner(page,limit);
        return map;
    }



}
